package com.grass.p019lv.novel.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.androidsa.bttsddka.R;
import com.androidx.p013lv.base.bean.UserInfo;
import com.androidx.p013lv.base.bean.novel.FictionBean;
import com.androidx.p013lv.base.bean.novel.FictionList;
import com.androidx.p013lv.base.bean.request.ReqLabelFiction;
import com.androidx.p013lv.base.dialog.BuyVipDialog;
import com.androidx.p013lv.base.http.BaseRes;
import com.androidx.p013lv.base.http.HttpUtils;
import com.androidx.p013lv.base.http.JsonParams;
import com.androidx.p013lv.base.http.UrlManager;
import com.androidx.p013lv.base.http.callback.HttpCallback;
import com.androidx.p013lv.base.interfaces.Key;
import com.androidx.p013lv.base.listener.ItemClickListener;
import com.androidx.p013lv.base.p015ui.LazyFragment;
import com.androidx.p013lv.base.utils.NetUtil;
import com.androidx.p013lv.base.utils.SpUtils;
import com.androidx.p013lv.base.utils.ToastUtils;
import com.google.gson.Gson;
import com.grass.p019lv.databinding.FragmentClassFictionBinding;
import com.grass.p019lv.novel.activity.VoiceNovelActivityNew;
import com.grass.p019lv.novel.adapter.AudioFictionCAdapter;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshLoadMoreListener;

/* renamed from: com.grass.lv.novel.fragment.AudioFictionCFragment */
public class AudioFictionCFragment extends LazyFragment<FragmentClassFictionBinding> implements ItemClickListener, OnRefreshLoadMoreListener {
    AudioFictionCAdapter adapter;
    private int classifyId;
    private int page = 1;

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public int setFragmentView() {
        return R.layout.fragment_class_fiction;
    }

    public static AudioFictionCFragment newInstance(int i) {
        Bundle bundle = new Bundle();
        bundle.putSerializable("classifyId", Integer.valueOf(i));
        AudioFictionCFragment audioFictionCFragment = new AudioFictionCFragment();
        audioFictionCFragment.setArguments(bundle);
        return audioFictionCFragment;
    }

    @Override // androidx.fragment.app.Fragment
    public void setArguments(Bundle bundle) {
        super.setArguments(bundle);
        if (bundle != null) {
            this.classifyId = bundle.getInt("classifyId");
        }
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void initViews() {
        ((FragmentClassFictionBinding) this.binding).refresh.setOnRefreshListener(this);
        ((FragmentClassFictionBinding) this.binding).refresh.setOnLoadMoreListener(this);
        ((FragmentClassFictionBinding) this.binding).recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
        this.adapter = new AudioFictionCAdapter();
        ((FragmentClassFictionBinding) this.binding).recycler.setAdapter(this.adapter);
        this.adapter.setItemListener(this);
        ((FragmentClassFictionBinding) this.binding).statusLayout.setOnRetryListener(new View.OnClickListener() {
            /* class com.grass.p019lv.novel.fragment.AudioFictionCFragment.View$OnClickListenerC31691 */

            public void onClick(View view) {
                AudioFictionCFragment.this.page = 1;
                AudioFictionCFragment.this.getInfo();
            }
        });
    }

    @Override // com.androidx.p013lv.base.p015ui.LazyFragment
    public void onFirstUserVisible() {
        super.onFirstUserVisible();
        this.page = 1;
        getInfo();
    }

    /* access modifiers changed from: package-private */
    public void getInfo() {
        if (this.page == 1) {
            if (!NetUtil.isNetworkAvailable()) {
                ((FragmentClassFictionBinding) this.binding).statusLayout.showNoNet();
                return;
            }
            ((FragmentClassFictionBinding) this.binding).statusLayout.showLoading();
        }
        ReqLabelFiction reqLabelFiction = new ReqLabelFiction();
        reqLabelFiction.setClassId(this.classifyId);
        reqLabelFiction.setFictionType(2);
        reqLabelFiction.setOrderType(1);
        reqLabelFiction.setPage(this.page);
        reqLabelFiction.setPageSize(30);
        String json = new Gson().toJson(reqLabelFiction);
        HttpUtils.getInsatance().post(UrlManager.getInsatance().postFictionFindList(), json, new HttpCallback<BaseRes<FictionBean>>("postFictionFindList") {
            /* class com.grass.p019lv.novel.fragment.AudioFictionCFragment.C31702 */

            public void onLvSuccess(BaseRes<FictionBean> baseRes) {
                ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).statusLayout.hideLoading();
                ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).refresh.finishRefresh();
                ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).refresh.finishLoadMore();
                if (baseRes.getCode() == 200) {
                    if (baseRes.getData() != null && baseRes.getData().getData() != null && baseRes.getData().getData().size() > 0) {
                        AudioFictionCFragment.this.adapter.setDomain(baseRes.getData().getDomain());
                        if (AudioFictionCFragment.this.page == 1) {
                            AudioFictionCFragment.this.adapter.setData(baseRes.getData().getData());
                            return;
                        }
                        ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).refresh.resetNoMoreData();
                        AudioFictionCFragment.this.adapter.setDatasInEnd(baseRes.getData().getData());
                    } else if (AudioFictionCFragment.this.page == 1) {
                        ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).statusLayout.showEmpty();
                    } else {
                        ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).refresh.finishLoadMoreWithNoMoreData();
                    }
                } else if (AudioFictionCFragment.this.page == 1) {
                    ((FragmentClassFictionBinding) AudioFictionCFragment.this.binding).statusLayout.showError();
                } else {
                    ToastUtils.getInstance().showWeak(baseRes.getMsg());
                }
            }
        });
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onResume() {
        super.onResume();
        getUserInfo();
    }

    public void getUserInfo() {
        HttpUtils.getInsatance().post(UrlManager.getInsatance().userInfo(), JsonParams.build().commit(), new HttpCallback<BaseRes<UserInfo>>("userInfo") {
            /* class com.grass.p019lv.novel.fragment.AudioFictionCFragment.C31713 */

            public void onLvSuccess(BaseRes<UserInfo> baseRes) {
                if (baseRes.getCode() == 200) {
                    SpUtils.getInstance().setUserInfo(baseRes.getData());
                }
            }
        });
    }

    @Override // com.androidx.p013lv.base.listener.ItemClickListener
    public void onItemClick(View view, int i) {
        if (!isOnClick()) {
            if (SpUtils.getInstance().getUserInfo().getFreeWatches() != -1) {
                new BuyVipDialog(getContext()).show();
                return;
            }
            int fictionId = ((FictionList) this.adapter.getDataInPosition(i)).getFictionId();
            Intent intent = new Intent(getActivity(), VoiceNovelActivityNew.class);
            intent.putExtra(Key.NOVEL_ID, fictionId);
            getActivity().startActivity(intent);
        }
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnLoadMoreListener
    public void onLoadMore(RefreshLayout refreshLayout) {
        this.page++;
        getInfo();
    }

    @Override // com.scwang.smartrefresh.layout.listener.OnRefreshListener
    public void onRefresh(RefreshLayout refreshLayout) {
        this.page = 1;
        getInfo();
    }

    @Override // androidx.fragment.app.Fragment, com.gyf.immersionbar.components.ImmersionFragment
    public void onDestroy() {
        super.onDestroy();
        HttpUtils.getInsatance().cancelTag("postFictionFindList");
        HttpUtils.getInsatance().cancelTag("userInfo");
    }
}
